<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="/admin/lib/html5shiv.js"></script>
    <script type="text/javascript" src="/admin/lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui/css/H-ui.css"/>
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="/admin/lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/css/style.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="/admin/lib/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>工器具类型列表</title>
</head>

<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 基础信息 <span
        class="c-gray en">&gt;</span> 工器具类型管理
    <a class="btn btn-primary radius r" style="line-height:1.6em;margin-top:3px"
       href="javascript:location.replace(location.href);"
       title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<div class="page-container">
    <div class="cl pd-5 bg-1 bk-gray">
            <span class="">
                <a href="javascript:;" onclick="add('添加工器具类型','/{{config('constant.name_admin')}}/tool/add','','310')"
                   class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加工器具类型</a>
                <a href="javascript:;" onclick="add('查看工器具分类','/{{config('constant.name_admin')}}/tool/class/index','900','800')"
                   class="btn btn-primary radius">查看工器具分类</a>
                <!-- <a href="javascript:;" onclick="get_tool()" class="btn btn-primary radius">同步第三方信息</a> -->
            </span>
    </div>
    <div class="mt-20">
        <table class="table table-border table-bordered table-hover table-bg table-responsive" id="datatable">
            <thead>
            <tr class="text-c">
                <th>ID</th>
                <th>工器具名称</th>
                <th>分类</th>
                <th>单位</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
        </table>
    </div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/admin/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="/admin/lib/layer/3.1.1/layer.js"></script>
<script type="text/javascript" src="/admin/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="/admin/static/h-ui.admin/js/H-ui.admin.js"></script>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/admin/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>

<script type="text/javascript">
    var table;
    function get_tool(){
        $.ajax({
            data:{_token:"{{csrf_token()}}"},
            url:"/{{config('constant.name_admin')}}/RequestGwData/getTool",
            type:"post",
            dateType:"JSON",
            success:function (res){
                if (res.code==0){
                    layer.msg(res.msg,{icon:2})
                    return;
                }else{
                    layer.msg(res.msg,{icon:1,time:2000},function (){
                        window.location.reload()
                    })
                }
            },
            error:function (error) {
                layer.msg('ajax请求失败',{icon:2,time:2000},function (){
                    window.location.reload()
                })
            }
        })
    }
    $(function () {
        $.fn.dataTable.ext.errMode = 'throw';//datatable抛异常的方式，在console中输出，默认以alert的方式弹出
        table = $('#datatable').DataTable({
            // ordering: false, // 是否排序
            "deferRender": true,//延迟渲染速度
            ajax: "/{{config('constant.name_admin')}}/tool/index",
            processing: true,//加载数据时候是否显示进度条
            language: {url: '/admin/lib/datatables/dataTables_Chinese_Lang.json'},
            columns: [
                {data: "id", class: "text-c"},//
                {data: "name", class: "text-c"},//
                {data: "class_name", class: "text-c"},//
                {data: "unit", class: "text-c"},//
                {
                    data: "ishide",
                    class: "text-c",
                    searchable: false,
                    orderable: false,
                    render: function (data, type, row, meta) {
                        if (data === 0) {
                            return '<span class="label label-success radius" title="隐藏后业务受理时不会显示">显示</span>';
                        } else {
                            return '<span class="label label-default radius" title="隐藏后业务受理时不会显示">隐藏</span>';
                        }
                    }
                },
                {
                    data: null,
                    class: "text-c",
                    searchable: false,
                    orderable: false,
                    render: function (data, type, row, meta) {
                        return '<a class="btn btn-primary-outline radius size-MINI" href="javascript:;" onclick="rel_xxx(\'关联检验标准\',\'/{{config('constant.name_admin')}}/tool/relStd\',\'' + row.id + '\',\'\',\'\',true)">关联标准</a> ' +
                            '<a class="ml-5 btn btn-primary-outline radius size-MINI" href="javascript:;" onclick="rel_xxx(\'关联检验项目\',\'/{{config('constant.name_admin')}}/stdToolItemRel/relItem\',\'' + row.id + '\',\'\',\'\',true)" >关联项目</a>' +
                            '<a class="ml-5 btn btn-success-outline radius size-MINI" href="javascript:;" onclick="edit(\'编辑\',\'/{{config('constant.name_admin')}}/tool/edit\',' + row.id + ')" >编辑</a>' +
                            // '<a class="ml-5 btn btn-success-outline radius size-MINI" href="javascript:;" onclick="edit(\'铭牌属性\',\'/{{config('constant.name_admin')}}/tool/toolPlate\',' + row.id + ')" >铭牌属性</a>' +
                            ' <a href="javascript:;" onclick="del(' + row.id + ')" class="ml-5 btn btn-danger-outline radius size-MINI" >删除</a>';
                    }
                },//操作
            ]
        });

        /*  draw  在表格完成绘制后触发*/
        table.on('draw', function () {
            var info = table.page.info();
            //如果最后一页仅剩一条记录，而且不是在第一页
            if ((info.start == info.end) && info.end > 1) {
                //跳转到上一页
                $('#datatable_previous').click();
            }
        });
    });

    /*表格重新加载*/
    function table_reload(bool) {
        //清除表头 CheckBox的对勾
        // $("#datatable").find("thead").find("input[type=checkbox]").removeAttr('checked');
        if (bool) {
            //true时，跳到第一页
            table.ajax.reload();
        } else {
            //false时，停留在原来页
            table.ajax.reload(null, false);
        }
    }

    /*工器具类型 添加*/
    function add(title, url, w, h) {
        layer_show(title, url, w, h);
    }

    /*工器具类型 编辑*/
    function edit(title, url, id, w, h) {
        layer_show(title, url + '?id=' + id, w, h);
    }

    /*删除*/
    function del(id) {
        var index2;

        layer.confirm('确认要删除吗？', {title: '信息', icon: 3}, function (index) {
            $.ajax({
                type: 'GET',
                url: '/{{config('constant.name_admin')}}/tool/del' + '?id=' + id,
                // dataType: 'json',
                success: function (data) {
                    // console.log(data);
                    if (data === '1') {
                        table_reload(0);//0停留在当前页，1回到第一页
                        layer.msg('删除成功!', {icon: 1, time: 2000});
                    } else if (data === '2') {
                        layer.msg('该记录已被引用，禁止删除!<br>您可以隐藏它', {icon: 2, time: 5000});
                    } else {
                        layer.msg('删除失败!', {icon: 2, time: 2000});
                    }
                },
                error: function (data) {
                    ajax_error(data);
                },
                beforeSend: function () {
                    //0.4透明度 白色遮罩
                    index2 = layer.load(2, {shade: [0.05, '#000']});
                },
                complete: function () {
                    layer.close(index2);
                },
            });
        });
    }

    /*关联xxx*/
    function rel_xxx(title, url, id, w, h, full) {
        // w = $(window).width() - 50;
        layer_show(title, url + '?id=' + id, w, h, full);
    }

</script>
</body>

</html>
